<%--
  User: ${panhongwei}
  Date: 15-5-17
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
  <head>
    <title></title>
  </head>
  <body>
     当前缓存内容：<input type="button" onclick="listCache()" value="刷新" />
     <input type="button" onclick="showCache('/test/listArticle.do')" value="多对一" />
     <input type="button" onclick="showCache('/test/listUserArticle.do')" value="一对多" />
    <div id="cacheList">

    </div>
     新增缓存:
     <lable>name:<input type="text" id="key" /></lable>
     <lable>age:<input type="text" id="val" /></lable>
     <input type="button" onclick="addCache('/test/save.do')" value="新增" />
     <input type="button" onclick="addCache('/test/addException.do')" value="新增抛出异常" />
  </body>

      <script src="/asset-libs/js/jquery-2.1.0.min.js"></script>
      <script src="/asset-libs/js/jquery-1.11.0.min.js"></script>
      <script type="text/javascript">

          listCache();

          function listCache() {
              $.ajax({
                  url: "/test/listUser.do",
                  type: "post",
                  dataType: "json",
                  success: function (data) {
                      console.log(data);
                      if (data.code == "success") {
                          if (data.result.length > 0) {
                              $("#cacheList").empty();
                              var caches = data.result[0];
                              for (var i = 0; i < caches.length; i++) {
                                  var spanHtml = '<p><span>test1 id：' + caches[i].id + '</span>&nbsp;&nbsp;<span>name：' + caches[i].name + '</span>&nbsp;&nbsp;<span>age:' + caches[i].age + '</span></p>';
                                  $("#cacheList").append(spanHtml);
                              }
                              caches = data.result[1];
                              for (var i = 0; i < caches.length; i++) {
                                  var spanHtml = '<p><span>test2 id：' + caches[i].id + '</span>&nbsp;&nbsp;<span>name：' + caches[i].name + '</span>&nbsp;&nbsp;<span>age:' + caches[i].age + '</span></p>';
                                  $("#cacheList").append(spanHtml);
                              }
                          }
                      }
                  }

              })
          }

          function showCache(url) {
              $.ajax({
                  url: url,
                  type: "post",
                  dataType: "json",
                  success: function (data) {
                      if(data.code = "success"){
                          console.log(data.result);
                      }else {
                          console.log(data.msg);
                      }

                  }

              })
          }

          function addCache(url) {
              $.ajax({
                  url: url,
                  type: "post",
                  dataType: "json",
                  data:{name:$("#key").val(),age:$("#val").val()},
                  success: function (data) {
                      if (data.code == "success") {
                          listCache();
                      }
                  }

              })
          }
      </script>

</html>
